<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加服务</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>
    首页
    <span class="c-gray en">&gt;</span>
    会员管理
    <span class="c-gray en">&gt;</span>
    办卡管理
    <span class="c-gray en">&gt;</span>
    添加
</nav>
<div class="page-container">
    <div class="form-unit">基本信息</div>
        <div class="form-group" style="height:35px;">
            <label class="control-label col-xs-4 col-sm-3">会员卡类型：</label>
            <div class="formControls col-xs-4 col-sm-4">
                <select class="form-control" id="cardManageSelect">
                    <option>年卡</option>
                    <option>次卡</option>
                    <option>储值卡</option>
                </select>
            </div>
        </div>
        <!-- 年卡 -->
        <div id="cardManageYearCard">
            <form  method="post" class="form form-horizontal" id="cardManageYearCard-form-add">
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">手机号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageYearCardPhone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">车牌号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageYearCardCarNo" name="carNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageYearCardCardNo" name="cardNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">开卡时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="addTimes" id="cardManageYearCardAddTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">到期时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="endTimes" id="cardManageYearCardEndTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">办卡门店：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" placeholder="" name="shopId" id="cardManageYearCardShopId">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡描述：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="cardManageYearCardRemark" name="remark" cols="60" rows="5" class="textarea valid" placeholder="请输入会员卡的描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input onclick="cardManageAddFun.submitYearCard();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
            </form>
        </div>
        <!-- 次卡 -->
        <div id="cardManageTimesCard" style="display: none;">
            <form  method="post" class="form form-horizontal" id="cardManageTimesCard-form-add">
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">手机号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageTimesCardPhone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageTimesCardCardNo" name="cardNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">原始数量：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageTimesCardOrginalNum" name="orginalNum">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">开卡时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="addTimes" id="cardManageTimesCardAddTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">到期时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="endTimes" id="cardManageTimesCardEndTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">门店：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" placeholder="" name="shopId" id="cardManageTimesCardShopId">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡描述：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="cardManageTimesCardRemark" name="remark" cols="60" rows="5" class="textarea valid" placeholder="请输入会员卡的描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input onclick="cardManageAddFun.submitTimesCard();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
            </form>
        </div>
        <!-- 储值卡 -->
        <div id="cardManageValueCard" style="display: none;">
            <form  method="post" class="form form-horizontal" id="cardManageValueCard-form-add">
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">手机号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageValueCardPhone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">车牌号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageValueCardCarNo" name="carNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageValueCardCardNo" name="cardNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">储值金额：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageValueCardOrginalNum" name="orginalNum">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">开卡时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="addTimes" id="cardManageValueCardAddTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">到期时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true})" readonly="readonly" class="form-control Wdate" value="" name="endTimes" id="cardManageValueCardEndTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">门店：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" placeholder="" name="shopId" id="cardManageValueCardShopId">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡描述：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="cardManageValueCardRemark" name="remark" cols="60" rows="5" class="textarea valid" placeholder="请输入会员卡的描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input onclick="cardManageAddFun.submitValueCard();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
            </form>
        </div>
</div>
<script type="text/javascript">
    /*办卡管理，添加页面 cardManageAddFun*/
    var cardManageAddFun;

    cardManageAddFun={
        init : function () {
            $('#cardManageSelect').change(function(){
                var p1=$(this).children('option:selected').index();//这就是selected的值
                if(p1 == 0){
                    $("#cardManageYearCard").show();
                    $("#cardManageValueCard").hide();
                    $("#cardManageTimesCard").hide();
                }else if(p1 == 1){
                    $("#cardManageTimesCard").show();
                    $("#cardManageYearCard").hide();
                    $("#cardManageValueCard").hide();
                }else {
                    $("#cardManageValueCard").show();
                    $("#cardManageYearCard").hide();
                    $("#cardManageTimesCard").hide();
                }
            });

            //加载店名
            $.ajax({
                type: "GET",
                url: "biz/getAllShopsNameByBizId",
                dataType: "json",
                success: function (data) {
                    $("[name='shopId']").select2({
                        data: data,
                        placeholder: '请选择门店',
                        width: '380px'
                    });
                },
                error: function () {
                    alert("error2");
                }
            });
        },
        //提交(年卡)
        submitYearCard : function () {
            $.ajax({
                type: "GET",
                url: "cust/insertYearCard",
                data: $("#cardManageYearCard-form-add").serializeArray(),
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        platformClientCardManageFun.searchAction();
                    } else {
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error2");
                }
            });
        },
        //提交(储值卡)
        submitValueCard : function () {
            var temp = $("#cardManageValueCard-form-add").serializeArray();
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'orginalNum'){
                    temp[i].value = temp[i].value*100;
                }
            }
            $.ajax({
                type: "GET",
                url: "cust/insertValueCard",
                data: temp,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        platformClientCardManageFun.searchAction();
                    } else {
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error2");
                }
            });
        },
        //提交(次卡)
        submitTimesCard : function () {
            var temp = $("#cardManageTimesCard-form-add").serializeArray();
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'orginalNum'){
                    temp[i].value = temp[i].value*100;
                }
            }
            $.ajax({
                type: "GET",
                url: "cust/insertTimesCard",
                data: temp,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        platformClientCardManageFun.searchAction();
                    } else {
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error2");
                }
            });
        }
    };
    cardManageAddFun.init();
</script>
</body>
</html>